package com.wugui.datax.admin.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.google.common.collect.Lists;
import com.wugui.datax.admin.entity.JobDatasource;
import com.wugui.datax.admin.service.DatasourceGeneralQueryService;
import com.wugui.datax.admin.service.JobDatasourceService;
import com.wugui.datax.admin.tool.query.BaseQueryTool;
import com.wugui.datax.admin.tool.query.HBaseQueryTool;
import com.wugui.datax.admin.tool.query.MongoDBQueryTool;
import com.wugui.datax.admin.tool.query.QueryToolFactory;
import com.wugui.datax.admin.util.JdbcConstants;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DatasourceGeneralQueryServiceImpl implements DatasourceGeneralQueryService {

    @Autowired
    private JobDatasourceService jobDatasourceService;

    /**
     * 通用查询
     *
     * @param condition
     * @return
     */
    @Override
    public Object generalQuery(JSONObject condition) {

        JobDatasource datasource = jobDatasourceService.getById(condition.getLong("dataBaseId"));
        //queryTool组装
        if (ObjectUtil.isNull(datasource)) {
            return Lists.newArrayList();
        }

        /*BaseQueryTool qTool = QueryToolFactory.getByDbType(datasource);

        //自主实现
        if (JdbcConstants.HBASE.equals(datasource.getDatasource())) {

        } else if (JdbcConstants.MONGODB.equals(datasource.getDatasource())) {

        }

        StringBuilder sql = new StringBuilder("SELECT ");
        //支持查询指定列
        sql.append(qTool.exampleSelectColumns(condition));
        sql.append(qTool.fromTable(condition));
        sql.append(qTool.exampleWhereClause(condition));
        sql.append(qTool.exampleOrderBy(condition));
        sql.append(qTool.examplePage(condition));

        String querySql = sql.toString();

        qTool.getColumnsByQuerySql()
        //通用实现*/

        return null;
    }

}
